
*Graph settings
set scheme stcolor // need stata 18 for this
grstyle init
grstyle set plain, horizontal grid noextend 
grstyle set ci
grstyle color major_grid gs14
grstyle linepattern major_grid dash




*Bring in data
use "${ddata}cleaned_data_wACSweight.dta", clear

*Collapse
drop if missing(state)

forval x=1/6 {
	gen agree_disagree_`x' = qgn6_`x' if qgn6_`x'<=5	
}
forval x = 2/5 {
	replace agree_disagree_`x' = 5 - agree_disagree_`x'
}
forval x = 1/5{
	qui sum agree_disagree_`x', d
	gen agree_index_`x' = (agree_disagree_`x' - `r(mean)')/`r(sd)'	
}	
egen agree_index = rowmean(agree_index_*)


collapse (mean) qs1 agree_index [aw = weight], by(state)

*Create x_axis
egen x_axis = group(agree_index)
labmask x_axis, values(state)

*Regression 
reg qs1 x_axis, robust
foreach rhs in x_axis _cons {
	loc star
	loc p = (2 * ttail(e(df_r), abs(_b[`rhs']/_se[`rhs'])))
	if `p' <= 0.10 local star "*"
	if `p' <= 0.05 local star "**"
	if `p' <= 0.01 local star "***"
	local beta = _b[`rhs']
	local beta_form = string(`beta', "%3.2f")
	local x`rhs'_form = "`beta_form'`star'"	
}

*Note
local note "Equation estimate: FO Belief = `x_cons_form' + `xx_axis_form' x State Rank"

*Max of y-axis
local max = 70

*Scatter
tw scatter qs1 x_axis || lfit qs1 x_axis, ylab(10(5)`max') leg(off) ///
	xlab(1(1)51, valuelabels nogrid labsize(1.3)) xtitle("") ///
	ytitle("FO Belief (Mother Should Reject Offer)") ///
	note("`note'")

*Export
graph export "${o}qs1_bystate_binscatter_weighted.pdf", replace


